<?xml version="1.0"?>
<jsp:root 	xmlns:jsp="http://java.sun.com/JSP/Page"
 			xmlns:c="http://java.sun.com/jsp/jstl/core"
 			xmlns="http://www.w3.org/1999/xhtml"
 			version="2.1">
 
 <jsp:directive.page contentType="text/html" pageEncoding="UTF-8" />
 <jsp:directive.page isELIgnored="false" />
 <jsp:output 	omit-xml-declaration="false" 
 			 	doctype-root-element="HTML" 
 				doctype-system="about:legacy-compat" />
 
 <jsp:useBean id="datosLogin" class="es.javamyadmin.beans.LoginBean" scope="session" />
 
 <jsp:useBean id="listaUsuariosBean" class="es.javamyadmin.beans.ListaUsuariosBean" scope="session" />
 <jsp:setProperty property="user" name="listaUsuariosBean" value="${datosLogin.usuario}" />
 <jsp:setProperty property="pass" name="listaUsuariosBean" value="${datosLogin.password}" />
 <jsp:setProperty property="host" name="listaUsuariosBean" value="${datosLogin.servidor}" />
 <jsp:setProperty property="port" name="listaUsuariosBean" value="${datosLogin.puerto}" />
 <jsp:setProperty property="clausulaWhere" name="listaUsuariosBean" value="" />

<html>
<head>

<link rel="icon" href="${pageContext.request.contextPath}/images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="${pageContext.request.contextPath}/images/favicon.ico" type="image/x-icon" />

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/java-admin.css" media="screen" />

<script src="${pageContext.request.contextPath}/js/jquery.js"><!-- N --></script>
<script src="${pageContext.request.contextPath}/js/bootstrap-transition.js"><!-- N --></script>
<script src="${pageContext.request.contextPath}/js/bootstrap-modal.js"><!-- N --></script>
<script src="${pageContext.request.contextPath}/js/ajaxCargarMsjConfirmacion.js"><!-- N --></script>

<title>JavaMyAdmin</title>

<script>
	$(document).ready(function() {
		$('#windowTitleDialog').bind('show', function () {
			
		});
	});
	function closeDialog () {
		$('#windowTitleDialog').modal('hide'); 
	};
	function okClicked () {
		closeDialog ();
	};	
</script>

</head>

<body>
<div id="wrapper">
<div id="todo">

<div id="contenedor">
	
	<jsp:include page="../includes/sidebar-left.jsp" />
	
	<div id="contenido">
	
		<jsp:include page="../includes/cabecera.jsp" />
		
		<h2>Usuarios MySQL</h2>
		
		<!-- Error de conexión -->
		<c:if test="${error!=null}"><div id="ko"  class="aviso"><div class="pro_aviso ko"><p>${error }<c:if test="${descripcion != null}"><a id="especial" data-toggle="modal" href="#windowTitleDialog" onclick="cargarDatosMsj('6', '${descripcion}', '');" style="font-size:'10px'; "> (más)</a></c:if></p></div></div></c:if>		
		<c:if test="${ok!=null}"><div class="aviso"><div class="pro_aviso ok"><p><c:out value="${ok}"></c:out></p></div></div></c:if>
		<c:if test="${warning!=null}"><div id="warning"  class="aviso"><div class="pro_aviso alert"><p>${warning }</p></div></div></c:if>
		
		<!-- VENTANA EMERGENTE DE CONFIRMACIÓN -->
		<div id="windowTitleDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="windowTitleLabel" aria-hidden="true">
			<!-- se cargará el mensaje por ajax -->
		</div>
		<!-- FIN VENTANA EMERGENTE -->
		
		<input class="boton" type="button" onclick="window.location='${pageContext.request.contextPath}/jsp/crear-usuario.jsp'" value="CREAR USUARIO"/>
		
		<table id="lista-usuarios">
			<tr>
				<th class="inicio" style="width: 33%;">HOST</th>
				<th style="width: 33%;">USUARIO</th>
				<th class="fin" style="width: 33%;">ACCIONES</th>
			</tr>
					
			<c:choose>
				<c:when test="${listaUsuariosBean.usuarios.size()==0}">
					<tr>
						<td colspan="3" align="center">No hay usuarios o no tienes permisos para listarlos.</td>
					</tr>
				</c:when>
			
				<c:when test="${listaUsuariosBean.usuarios.size()>0}">
					<c:forEach var="lista" items="${listaUsuariosBean.usuarios}">			
						<tr>
							<td align="center"><c:out value="${lista.host}"></c:out></td>
							<td align="center"><c:out value="${lista.user}"></c:out></td>
							<td align="center">
								<a href="${pageContext.request.contextPath}/jsp/ver-permisos-usuario.jsp?usuarioSQL=${lista.user}&amp;hostSQL=${lista.host}" title="ver permisos"><img class="margen" src="${pageContext.request.contextPath}/images/icons/ver.png" width="20" height="20" alt="ver"/></a>
								<a href="${pageContext.request.contextPath}/jsp/editar-usuario.jsp?usuarioSQL=${lista.user}&amp;hostSQL=${lista.host}" title="editar usuario"><img class="margen" src="${pageContext.request.contextPath}/images/icons/editar.png" width="20" height="20" alt="editar"/></a>
								<c:if test="${lista.user==datosLogin.usuario and lista.host==datosLogin.servidor }">
									<a href="#"><img style="opacity:0.2; cursor: default;" class="margen" src="${pageContext.request.contextPath}/images/icons/eliminar.png" width="20" height="20" alt="eliminar"/></a>
								</c:if>
								<c:if test="${lista.user!=datosLogin.usuario or lista.host!=datosLogin.servidor }">
									<a data-toggle="modal" href="#windowTitleDialog" onclick="cargarDatosMsj('4', '${lista.user}', '${lista.host}');" title="eliminar usuario"><img class="margen encima" src="${pageContext.request.contextPath}/images/icons/eliminar.png" width="20" height="20" alt="eliminar"/></a>
								</c:if>
														
							</td>
						</tr>
					</c:forEach>
				</c:when>
			</c:choose>	
		</table>
		
	</div>

</div>
</div>
</div>
</body>
</html>
</jsp:root>